//
//  SSRetweetView.swift
//  weibo
//
//  Created by 邵帅 on 16/6/27.
//  Copyright © 2016年 groupNineObject. All rights reserved.
//

import UIKit
import SnapKit

class SSRetweetView: UIView {
    
    var bottomConstraint: Constraint?
    
    var  retweetModel: SSStatusCellModel? {
        
        didSet {
            
            contentLbl.attributedText = retweetModel?.retweetAttributeText
            
            bottomConstraint?.uninstall()
            
            if retweetModel?.model?.retweet_status?.picture_urls?.count > 0 {
                
                pictrueView.hidden = false
                
                self.snp_updateConstraints(closure: { (make) in
                    
                    self.bottomConstraint = make.bottom.equalTo(pictrueView).constraint
                })
                
                pictrueView.pic_urls = retweetModel?.model?.retweet_status?.picture_urls
            }else {
                
                pictrueView.hidden = true
                
                self.snp_updateConstraints(closure: { (make) in
                    
                    self.bottomConstraint = make.bottom.equalTo(contentLbl).constraint
                })
            }
            
            
        }
    
    }
    

    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        addSubview(contentLbl)
        addSubview(pictrueView)
        
        contentLbl.snp_makeConstraints { (make) in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(pictrueView.snp_top)
            
        }
        
        pictrueView.snp_makeConstraints { (make) in
            
            make.left.equalTo(self.snp_left)
            
            make.height.equalTo(100)
            make.width.equalTo(100)
            
        }
        
        self.snp_makeConstraints { (make) in
            
            self.bottomConstraint = make.bottom.equalTo(pictrueView).constraint
        }
        
    }
    
    // 懒加载控件
    private lazy var contentLbl: UILabel = {
        
        let label = UILabel()
        
        label.textColor = UIColor.darkGrayColor()
        
        label.font = UIFont.systemFontOfSize(16)
        
        label.text = "转发微博"
        
        label.numberOfLines = 0
        
        return label
        
    }()

    private lazy var pictrueView: SSPictureView = SSPictureView()
}
